/*
 This file is part of BTStracker
		
    BTStracker is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    BTStracker is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.	
	author: azbest.pro (azbest.pro@gmail.com)
*/
package pl.vdl.azbest.log;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Scanner;
import java.util.TimeZone;

import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory.Woodstox;

public class Tets {
	public static void main(String[] args) {

		// get zones
		String[] tzones = TimeZone.getAvailableIDs();
		ArrayList<String> groups = new ArrayList<String>();

		// filtering groups of tzones
		for (int j = 0; j < tzones.length; j++) {
			// System.out.println(j + " - " + tzones[j]);
			String selected = "";
			if (tzones[j].indexOf("/") > 0) {
				selected = tzones[j].substring(0, tzones[j].indexOf("/"));
			} else {
				selected =tzones[j];
			}
			

			selected = selected.trim();
			if (!groups.contains(selected))
				groups.add(selected);
		}

		// print our groups
		for (int j = 0; j < groups.size(); j++) {
			System.out.print(j + " - " + groups.get(j)+"   ");
			if(j%5==0) System.out.println("");
		}
		System.out.println(">");
		Scanner s = new Scanner(System.in);
		String line;
		boolean grShown = false;  
		while (s.hasNext()) {
			line = s.nextLine();
			int i;

			try {
				if ((i = Integer.parseInt(line)) > 0 && (i < tzones.length)&&!grShown) {
					showZonesOfGroup(groups.get(i));
					grShown = true;
				}
				if ((i = Integer.parseInt(line)) > 0 && (i < tzones.length)&&grShown) {
					printDate(groups.get(i));
					grShown = false;
					System.exit(0);
				}
				

			} catch (NumberFormatException e) {
				System.out.println("Type integer from list above");
			}

		}

		/*
		 * sun.util.calendar.ZoneInfo [
		 * 
		 * id="America/Los_Angeles",
		 * 
		 * offset=-28800000,
		 * 
		 * dstSavings=3600000, useDaylight=true, transitions=185,
		 * lastRule=java.util.SimpleTimeZone [id=America/Los_Angeles,
		 * offset=-28800000, dstSavings=3600000, useDaylight=true, startYear=0,
		 * startMode=3, startMonth=2, startDay=8, startDayOfWeek=1,
		 * startTime=7200000, startTimeMode=0, endMode=3, endMonth=10, endDay=1,
		 * endDayOfWeek=1 ,endTime=7200000, endTimeMode=0]]
		 * 
		 * 
		 * 
		 */

	}

	private static void showZonesOfGroup(String group) {

		String[] tzones = TimeZone.getAvailableIDs();
		for (int j = 0; j < tzones.length; j++) {
			if (tzones[j].contains(group)) {
				System.out.println(j + " - " + tzones[j]);
			}
		}
	}

	private static void printDate(String tzone) {
		Date d = new Date();
		TimeZone tz = TimeZone.getTimeZone(tzone);
		Calendar c = Calendar.getInstance(tz);
		c.setTime(d);
		System.out.println(c.get(c.HOUR_OF_DAY) + ":" + c.get(c.MINUTE) + ":"
				+ c.get(c.SECOND) + " ::" + c.get(c.AM_PM) + " "
				+ c.getTimeZone().getID());

		DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL,
				DateFormat.FULL, new Locale("en", "US"));
		System.out.println(df.format(d));

	}

}
